import scrapy


class DoubanSpider(scrapy.Spider):
  name = 'douban'
  # allowed_domains = ['movie.douban.com/top250?start=25']
  start_urls = ['http://movie.douban.com/top250?start=%d' % i * 25 for i in range(10)]

  # Spider指定管道的代码

  custom_settings = {
    'ITEM_PIPELINES': {'scrapy_demo.pipelines.Doubanipeline': 100, },
  }

  def parse(self, response):
    names = response.xpath('//div[@class="hd"]/a/span[1]/text()').extract()
    scores = response.xpath('//div[@class="star"]/span[2]/text()').extract()
    for n, s in zip(names, scores):
      yield {'name': n, 'score': s}
